package com.evenmo.hrms.mapper.oldmapper;

import com.evenmo.hrms.mapper.oldmapper.dynaSqlProvider.NoticeDynaSqlProvider;
import com.evenmo.hrms.pojo.Notice;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface NoticeMapper {

    //动态查询

    /**
     * 动态查询
     *
     * @param notice 查询参数信息
     * @return 符合条件的通知列表
     */
    @SelectProvider(type = NoticeDynaSqlProvider.class, method = "selectByParams")
    @ResultMap("noticeResultMapHaveUserId")
    public List<Notice> selectByParams(Notice notice);
    // 根据ID查询

    /**
     * 根据ID查询
     *
     * @param id 通知ID
     * @return 符合条件的通知
     */
    @Select("select * from notice where id=#{id}")
    @Results(id = "noticeResultMapHaveUserId", value = {
            @Result(column = "userId", property = "userId"),
            @Result(column = "userId", property = "user", one = @One(select = "com.evenmo.hrms.mapper.oldmapper.UserMapper.selectById", fetchType = FetchType.EAGER))
    })
    public Notice selectById(Integer id);

    //动态插入
    @InsertProvider(type = NoticeDynaSqlProvider.class, method = "insertByParams")
    public int insertByParams(Notice notice);

    /**
     * 查询所有的通知
     * @return 所有的通知列表
     */
    public List<Notice> selectNotices();
// 动态修改
    /**
     * 动态修改通知
     * @param notice 通知对象
     * @return 修改的数量
     */
    @UpdateProvider(type = NoticeDynaSqlProvider.class,method = "updateByParams")
    public int updateByParams(Notice notice);

    /**
     * 通过id删除
     * @param noticeId 通知ID
     * @return 删除的数量
     */
    @Delete("delete from notice where id=#{id}")
    public int deleteById(Integer noticeId);


}
